package com.example.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.vo.Result;
import com.example.sys.entity.Leaved;
import com.example.sys.service.ILeavedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuage
 * @since 2023-12-24
 */
@RestController
@RequestMapping("/leave")
public class LeavedController {
    @Autowired
    private ILeavedService leavedService;

    @GetMapping("/{id}")
    private Result<List<Leaved>> getLeaveList(@PathVariable Integer id){
        QueryWrapper<Leaved> leaveQueryWrapper = new QueryWrapper<>();
         leaveQueryWrapper.eq("user_id",id);
        List<Leaved> leaves = leavedService.list(leaveQueryWrapper);
        return Result.success(leaves);
    }


    @PostMapping("/addleave")
    public Result<?> addUser(@RequestBody Leaved leaved){

        leavedService.addleave(leaved);
        return Result.success("新增请假成功");
    }

    @DeleteMapping("/deletleave/{id}")
    public Result<?> deleteLeaveById(@PathVariable Integer id){

        leavedService.removeById(id);
        return Result.success("删除请假成功");
    }

    @GetMapping("/leavemsg/{id}")
    public Result<Leaved> getLeaveMsg(@PathVariable Integer id){
        Leaved leaved = leavedService.getById(id);
        return Result.success(leaved);
    }

    @PutMapping("/updateleave")
    public Result getLeaveMsg(@RequestBody Leaved leaved){

        leavedService.updateById(leaved);
        return Result.success("修改成功");
    }

    @GetMapping("/all")
    public Result<List<Leaved>> getLeaveAllList(){
        List<Leaved> list = leavedService.list();
        return Result.success(list);
    }

}

